package com.alibaba.shardingtest.config;

import com.zaxxer.hikari.HikariDataSource;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.util.Map;

@Configuration
@ConfigurationProperties(prefix = "sharding")
@Data
@ToString
@Slf4j
public class ShardingProperties {

    private Mode mode;

    private Map<String, ShardingDataSourceProperties> dataSources;

    @Data
    @ToString
    public static class Mode {
        private String type;
        private Repository repository;
    }

    @Data
    @ToString
    public static class Repository {
        private String type;
    }


    @EqualsAndHashCode(callSuper = true)
    @ToString
    @Data
    public static class ShardingDataSourceProperties extends HikariDataSource {
        @Value("${driverClassName}")
        private String driverClassName;
        @Value("${jdbcUrl}")
        private String jdbcUrl;
        private String username;
        private String password;

        public void setDriverClassName(String driverClassName) {
            super.setDriverClassName(driverClassName);
            this.driverClassName = driverClassName;
        }

        public void setJdbcUrl(String jdbcUrl) {
            super.setJdbcUrl(jdbcUrl);
            this.jdbcUrl = jdbcUrl;
        }

        public void setUsername(String username) {
            super.setUsername(username);
            this.username = username;
        }

        public void setPassword(String password) {
            super.setPassword(password);
            this.password = password;
        }
    }


}
